package com.yys.excel.yysexcel.utils.easyPoi;


import org.apache.poi.ss.usermodel.*;

/**
 * 注释
 *
 * @author lys
 * @date 2022/11/24
 */
public class ExcelStyleUtils {
    //头部标题样式
    public static CellStyle headerStyle(CellStyle cellStyle, Font font, int fontSize) {
        font.setBold(true);
        font.setFontHeightInPoints((short) fontSize);
        cellStyle.setFont(font);
        cellStyle = czSpCenter(cellStyle);
        return border(cellStyle);
    }

    //无边框
    public static CellStyle borderNone(CellStyle cellStyle) {
        //下边框
        cellStyle.setBorderBottom(BorderStyle.NONE);
        //左边框
        cellStyle.setBorderLeft(BorderStyle.NONE);
        //上边框
        cellStyle.setBorderTop(BorderStyle.NONE);
        //右边框
        cellStyle.setBorderRight(BorderStyle.NONE);
        return czSpCenter(cellStyle);
    }

    //上边框
    public static CellStyle borderTop(CellStyle cellStyle) {
        cellStyle.setBorderTop(BorderStyle.THIN);
        return cellStyle;
    }

    //上下左右边框,自动换行
    public static CellStyle border(CellStyle cellStyle) {
        //下边框
        cellStyle.setBorderBottom(BorderStyle.THIN);
        //左边框
        cellStyle.setBorderLeft(BorderStyle.THIN);
        //上边框
        cellStyle.setBorderTop(BorderStyle.THIN);
        //右边框
        cellStyle.setBorderRight(BorderStyle.THIN);
        //自动换行
        cellStyle.setWrapText(true);
        return cellStyle;
    }


    //垂直居中，和水平居中
    public static CellStyle czSpCenter(CellStyle cellStyle) {
        //垂直居中
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        //水平居中
        cellStyle.setAlignment(HorizontalAlignment.CENTER);
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        return cellStyle;
    }

    //左对齐
    public static CellStyle zdq(CellStyle cellStyle) {
        //垂直居中
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        //水平居中
        cellStyle.setAlignment(HorizontalAlignment.LEFT);
        return cellStyle;
    }

    //右对齐
    public static CellStyle ydq(CellStyle cellStyle) {
        //垂直居中
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        //水平居中
        cellStyle.setAlignment(HorizontalAlignment.RIGHT);
        return cellStyle;
    }
}
